/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ssp.event;

import ssp.service.FrontendServer;
import ssp.service.FrontendServerManager;
import ssp.service.ServiceEntry;
import ssp.utility.PropertyManager;

/**
 * サービスマップを更新するイベント
 * @author yamazaki
 */
public class ServiceMapUpdateEvent extends Event {
    
    //更新間隔
    private final double t = PropertyManager.getValueAsDouble("ServiceMapUpdateInterval");
    
    /**
     * コンストラクタ
     * @param eventTime イベント時間
     */
    public ServiceMapUpdateEvent(double eventTime) {
        super(eventTime);
    }

    @Override
    public void fire() {
        for(FrontendServer frontendServer : FrontendServerManager.getINSTANCE().getFrontendServerList()) {
            for(ServiceEntry entry : frontendServer.getServiceEntryList()) {
                frontendServer.updateServiceMap(entry, getEventTime());
            }
            frontendServer.updateProvidingService(getEventTime());
        }
        
        if(t > 0) {
            EventQueue eventQueue = EventQueue.getINSTANCE();
            eventQueue.addEvent(new ServiceMapUpdateEvent(eventQueue.getCurrentTime() + t));
        }
    }
    
}
